package org.ucas.faker.web.entity.patents;

import org.ucas.faker.web.fetcher.annotation.Connection;
import org.ucas.faker.web.fetcher.annotation.JoinCond;
import org.ucas.faker.web.utils.model.RawPatent;

import javax.persistence.*;

@Entity
@Table(name = "agency")
@Connection(table = "patent_agency", conds = {
    @JoinCond(column = "id", target = "agencyId")
})
public class Agency implements Patentable {

  public static enum Category {
    APPLICANT,
    ASSIGNEE,
    INVENTOR;

    @Override
    public String toString() {
      return (new Integer(this.ordinal())).toString();
    }
  }

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

  @Column(name = "wx_id")
  private String wxId;

  @Column(name = "name")
  private String name;

  @Column(name = "address")
  private String address;

  @Column(name = "country")
  private String country;

  @Column(name = "kind")
  private Category kind;

  public Agency(Category kind) {
    this.kind = kind;
  }

  public Agency() {
  }

  public void of(RawPatent patent, boolean overwrite) {
    Agency src = null;
    switch (kind) {
      case APPLICANT:
        src = patent.next(patent.applicants);
        break;
      case ASSIGNEE:
        src = patent.next(patent.pa);
        break;
      case INVENTOR:
        src = patent.next(patent.in);
        break;
    }

    if(src == null) return;

    this.<Agency>of(src,true);
  }

  public void to(RawPatent patent, boolean overwrite) {
    switch (kind) {
      case INVENTOR:
        patent.in.add(this);
        break;
      case ASSIGNEE:
        patent.pa.add(this);
        break;
      case APPLICANT:
        patent.applicants.add(this);
        break;
    }
  }

  public Long getId() {
    return id;
  }

  public void setId(Long id) {
    this.id = id;
  }

  public String getWxId() {
    return wxId;
  }

  public void setWxId(String wxId) {
    this.wxId = wxId;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getAddress() {
    return address;
  }

  public void setAddress(String address) {
    this.address = address;
  }

  public String getCountry() {
    return country;
  }

  public void setCountry(String country) {
    this.country = country;
  }

  public Category getKind() {
    return kind;
  }

  public void setKind(Category kind) {
    this.kind = kind;
  }
}
